package cn.xfdzx.android.apps.shop.adapter;

import android.annotation.SuppressLint;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.GoodsLiblaryListBean;
import cn.xfdzx.android.apps.shop.bean.OneCategoryBeen;
import cn.xfdzx.android.apps.shop.util.ImageGlideUtil;

/**
 * Creator: zf.
 * Date: 2020/8/1.
 * Description:商品库 头部分类.
 */
public class ShopInGoodsCatoryListAdapter extends BaseQuickAdapter<OneCategoryBeen.DataBean, BaseViewHolder>  {
    private OnItemItemCatoryClickListener onItemOnClickListener;
    private List<OneCategoryBeen.DataBean> catoryDate = new ArrayList<>();//分类列表
    private int oldPosition = 0;
    public ShopInGoodsCatoryListAdapter(@Nullable List<OneCategoryBeen.DataBean> data) {
        super(R.layout.item_goodscatory, data);
    }

    @Override
    public void setData(int index, @NonNull OneCategoryBeen.DataBean data) {
        super.setData(index, data);
    }


    @SuppressLint("ResourceAsColor")
    @Override
    protected void convert(final BaseViewHolder viewHolder, final OneCategoryBeen.DataBean date) {
       //text_color_catorybtn shape_ffccooconner5
        TextView tv_title = viewHolder.getView(R.id.tv_title);

        tv_title.setText(date.getName());

        if (date.isCheck()){
            tv_title.setBackgroundResource(R.drawable.text_color_catorybtn);
            //tv_title.setTextColor(R.color.color_FFFFFF);
            tv_title.setTextColor(mContext.getResources().getColor(R.color.color_FFFFFF));
        }else {
            tv_title.setBackgroundResource(R.drawable.text_color_catorybtn_nor);
            tv_title.setTextColor(mContext.getResources().getColor(R.color.color_393939));
        }
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (oldPosition == viewHolder.getLayoutPosition()){
                    catoryDate.get(viewHolder.getLayoutPosition()).setCheck(true);
                }else {
                    catoryDate.get(viewHolder.getLayoutPosition()).setCheck(true);
                    if (oldPosition>=0){
                        catoryDate.get(oldPosition).setCheck(false);
                    }

                    oldPosition = viewHolder.getLayoutPosition();
                }
                onItemOnClickListener.onItemItemCatoryClick(viewHolder.getLayoutPosition(),catoryDate);

            }
        });


    }
    public void clearDatas(){
        mData.clear();
        notifyDataSetChanged();
    }
    public void refreshDatas(List<OneCategoryBeen.DataBean> list){
        this.catoryDate = list;
        super.replaceData(list);
    }


    public void setItemCatoryClickListener(OnItemItemCatoryClickListener listener){
        this.onItemOnClickListener = listener;
    }

    public interface OnItemItemCatoryClickListener {
        void onItemItemCatoryClick( int position,List<OneCategoryBeen.DataBean> catoryDate);
    }

}
